package com.csu.tingtian.controller;

import com.csu.tingtian.common.CommonResponse;
import com.csu.tingtian.entity.LegalFarm;
import com.csu.tingtian.entity.RentFarm;
import com.csu.tingtian.service.FarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/farm/")
public class FarmController {
    @Autowired
    private FarmService farmService;

    //商家上架农场，改变legalfarm中的状态为1
    @PutMapping("rentfarms/{farmname}")
    CommonResponse<String> changeStatus(@PathVariable("farmname") String farmName) {
        return farmService.changeStatus(farmName);
    }


    //商家上架农场，选择可种植的农产品
    @PostMapping("rentfarms/{farmname}/products/{id}")
    CommonResponse<RentFarm> insertRentFarm(@PathVariable("id") String id, @PathVariable("farmname") String farmName) {
        return farmService.insertRentFarm(id,farmName);
    }

    //获取所有出租农场的信息
    @GetMapping("rentfarms")
    CommonResponse<List<LegalFarm>> getAllRentFarm() {
        return farmService.getAllRentFarm();
    }


    //用户租赁农场后，更新该农场的farmFreeArea，即更新legalFarm表
    @PutMapping("rentfarms/{farmname}/area/{area}")
    CommonResponse<String> updateArea(@PathVariable("farmname") String farmName,@PathVariable("area") int area) {
        return farmService.updateArea(farmName,area);
    }

}
